package encryption;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

public class RSAEncryptor {
	
	public static final String algorithm = "RSA";
		
	public static final String PUBLIC_KEY_FILE = "C:/RSAKeys/public.key";
	
	public static byte[] encrypt(String text, PublicKey key) throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException{
		
		byte[] cipherText = null;
		
		Cipher cipher = Cipher.getInstance(algorithm);
		
		cipher.init(Cipher.ENCRYPT_MODE, key);
		
		cipherText = cipher.doFinal(text.getBytes());
		
		return cipherText;
		
	}

}
